package com.example.techstudy.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: ls
 * @date: 2022/3/23
 * @description:
 */
@Service
public class ThreadService implements ApplicationContextAware {

   private List<AbstractExecutor> executors = new ArrayList<>();


    public void wrapThread(){
        for (int i = 0; i < executors.size(); i++) {
            executors.get(i).exec();
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, AbstractExecutor> beans = applicationContext.getBeansOfType(AbstractExecutor.class);
        beans.forEach((k,v)-> executors.add(v));
    }
}
